/*function getCourse(week_num) {
	var url = 'js/course_test.json';
	$.getJSON(url, function(result) {
		$('#week_input').val(result.week_num);

		var sections = $('#course_tab tr');
		$.each(result.courses, function(i, c) {
			var td = sections.eq(c.section).children('td').eq(c.day);
			td.text(c.name + '@' + c.location);
		});
	})
}
*/

/**
 * 获取课程信息
 * @param  {number} week_num 周数
 */
function getCourse(week_num) {
	// 通过Ajax连接后台
	$.getJSON('qurey_course.php', { "week_num": week_num }, function(result) {
		// 设置周数显示
		$('#week_input').val(result.week_num);

		var sections = $('#course_tab tr');
		// 清空之前显示的课程
		sections.children('td').text('');

		// 填充课程
		$.each(result.courses, function(i, c) {
			var td = sections.eq(c.section).children('td').eq(c.day);
			var tdc = $('<div></div>').text(c.name + '@' + c.location);
			td.append(tdc);
		});
	})
}

$(function() {
	// 初始化跳转按钮
	$('#week_picker').on('submit', function() {
		getCourse($('#week_input').val());
		return false;
	});

	// 初始化全部课程按钮
	$('#show_all').on('click', function() {
		getCourse(0);
	});

	// 初次获取课程信息
	getCourse(1);
})
